package com.skyworth.web.order.domain;

import com.skyworth.web.ordermenu.OrderMenuModel;
import com.skyworth.web.ordermenu.OrderMenuRepository;
import com.skyworth.web.admin.user.repository.UserRepository;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by skyworth on 2016/6/23.
 */
@Entity
@Component
@Table(name="ff_order")
public class OrderModel {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Setter
	@Getter
	public long id;

	@Column(name="user_id")
	@Setter
	@Getter
	public String userId;

	@Column(name="store_id")
	@Setter
	@Getter
	public long storeId;

	@Column(name="user_name")
	@Setter
	@Getter
	public String userName;

	@Column(name="price")
	@Setter
	@Getter
	public float price;

	@Column(name="remark")
	@Setter
	@Getter
	public String content;

    @Setter
    @Getter
    public int state;

    @Setter
    @Getter
    public  int available;

	@Column(name="table_id")
	@Setter
	@Getter
	public long tableId;

	@Setter
	@Getter
	public int people;


	@Column(name="created_time")
	@Setter
	@Getter
	public Timestamp createdTime;

	/*@Transient
	private static UserRepository userRepository;*/
	@Column(name="original_price")
	@Setter
	@Getter
	public float originalPrice;

	@Column(name="parent_id")
	@Setter
	@Getter
	public long parentId;

	/*@Autowired
	public void setUserRepository(UserRepository userRepository){
		OrderModel.userRepository = userRepository;
	}
*/
	/*@Transient
	private static OrderMenuRepository orderMenuRepository;
	@Autowired
	private void setOrderMenuRepository(OrderMenuRepository repository){
		OrderModel.orderMenuRepository = repository;
	}
*/
	/*public List<OrderMenuModel> getMenus(){
		return orderMenuRepository.findByOrderId(this.id);
	}*/

	public String getCreatedTimeStr() {
		String tsStr = "";
		if(this.createdTime != null){
			DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			tsStr = sdf.format(this.createdTime);
		}

		return tsStr;
	}

}
